package main

import (
	"fmt"
	"time"
)

func main() {
	ch := make(chan int)
	go producer(ch)

	consumer(ch)

	//time.Sleep(time.Second * 1)
	//fmt.Println("over")
	//for {
	//	;
	//}
}

func producer(in chan<- int) {
	for i := 0; i < 10; i++ {
		in <- i * i
		fmt.Println("向channel中写入数据,",i*i)
	}
	close(in)
}

func consumer(out <-chan int) {
	for n := range out {
		fmt.Println("从channel中读取数据:", n)
		time.Sleep(time.Second*1)
	}
}
